package com.qk.controller;


import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.ActivityDto;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/activities")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @DeleteMapping("/{id}")
    public Result deleteActivityById(@PathVariable Integer id){
        activityService.deleteActivityById(id);
        return Result.success();
    }

    @PutMapping
    public Result updateActivity(@RequestBody Activity activity){
        activityService.updateActivity(activity);
        return Result.success();
    }

    @PostMapping
    public Result addActivity(@RequestBody Activity activity){
        activityService.addActivity(activity);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result findActivityById(@PathVariable Integer id){
        Activity activity = activityService.findActivityById(id);
        return Result.success(activity);
    }

    @GetMapping
    public Result findActivity(ActivityDto activityDto){
        PageResult<Activity> userPage = activityService.findActivity(activityDto);
        return Result.success(userPage);

    }
}
